package com.itcpeng.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itcpeng.dao.MemberDao;
import com.itcpeng.entity.PageResult;
import com.itcpeng.entity.QueryPageBean;
import com.itcpeng.pojo.Member;
import com.itcpeng.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.*;

@Service(interfaceClass = MemberService.class)
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberDao memberDao;

    //通过手机号码查询会员
    @Override
    public Member findByTelephone(String telephone) {
        return memberDao.findByTelephone(telephone);
    }

    //添加会员
    @Override
    public void add(Member member) {
        memberDao.add(member);
    }

    //统计会员数量
    @Override
        public List<Integer> findMemberCountByMonth(List<String> months) {
            List<Integer> list=new ArrayList<>();
            for (String month : months) {//2019.05
                month=month+".31";
                Integer count = memberDao.findMemberCountBeforeDate(month);
                list.add(count);
            }
            return list;
        }



    //会员档案分页
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        Page<Member> page = memberDao.findPage(queryPageBean.getQueryString());
        return new PageResult(page.getTotal(), page.getResult());
    }

    //体检状态分页
    @Override
    public PageResult findStatePage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        Page<Map> page = memberDao.findStatePage(queryPageBean.getQueryString());
        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public List<Map<String, Object>> getMemberReportByAge() {
        return memberDao.getMemberReportByAge();
    }

    @Override
    public List<Map<String, Object>> getMemberReportBySex() {
        return memberDao.getMemberReportBySex();
    }

}
